Skip to content

fix(web): recreate Cesium3DTileset and ClippingPlaneCollection when tile source changes - #150

Merged
airslice merged 4 commits into
feat/support-custom-providerfrom
fix/3DTileset
May 27, 2026
Merged

fix(web): recreate Cesium3DTileset and ClippingPlaneCollection when tile source changes#150
airslice merged 4 commits into
feat/support-custom-providerfrom
fix/3DTileset

Conversation

@ZTongci

@ZTongci ZTongci commented May 26, 2026

Copy link
Copy Markdown
Contributor

Fixed a bug where switching the 3D tileset source type (e.g. from OSM to URL) in the layer panel would not display the new tileset until the user toggled layer visibility off and on.

Overview

When switching between tile source types (osm → url, or changing the tileset URL), the Cesium3DTileset component was not being recreated because no key prop was set on it. This caused resium to attempt a prop update on the existing Cesium object, but url is a constructor-only option in CesiumJS and cannot be changed after instantiation — so the tileset silently stayed on the old source.
A secondary but more critical issue was in how ClippingPlaneCollection was managed. It was created once via useState and shared across the lifetime of the Tileset component. When a Cesium3DTileset is destroyed (on unmount), CesiumJS internally calls destroy() on its attached ClippingPlaneCollection. With the key-based fix in place, unmounting the old tileset would destroy the shared collection, and the newly mounted tileset would receive an already-destroyed ClippingPlaneCollection, causing it to silently fail to render.

Toggling visibility worked as a workaround because it unmounted the entire Tileset React component, triggering a useState re-initialization that created a fresh ClippingPlaneCollection.

What I've done

  • Added a key prop to Cesium3DTileset derived from the tile source ("osm", "google", or the tileset URL string). When the source changes, React unmounts the old tileset and mounts a new one with the correct URL.
  • Changed ClippingPlaneCollection from useState (created once) to useMemo keyed on tilesetKey, so a fresh collection is created whenever the tileset source changes. This ensures the new Cesium3DTileset always receives a non-destroyed collection.

Affected File

web/src/classic/components/molecules/Visualizer/Engine/Cesium/Tileset/index.tsx

What I haven't done

How I tested

Which point I want you to review particularly

Memo

@ZTongci
ZTongci requested a review from airslice as a code owner May 26, 2026 07:57
@github-actions github-actions Bot added the web label May 26, 2026
@github-actions
github-actions Bot requested a review from mkumbobeaty May 26, 2026 07:57
@ZTongci
ZTongci changed the base branch from main to feat/support-custom-provider May 26, 2026 08:01
Comment thread web/src/classic/components/molecules/Visualizer/Engine/Cesium/Tileset/index.tsx Outdated
@wilfredmulenga
wilfredmulenga self-requested a review May 26, 2026 10:14
@airslice
airslice merged commit 4948e16 into feat/support-custom-provider May 27, 2026
8 checks passed
@airslice
airslice deleted the fix/3DTileset branch May 27, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants